/***************************************************************************
 *  Filename: uartmessages.h
 *  Class: 
 *  
 *  Copyright 2012  Jacco van der Spek
 *  <jaccovdspek@gmail.com>
 *
 *  Copyright 2012  Mario Henrique Voorsluys
 *  <forcaeluz@gmail.com>
 *  
 ****************************************************************************/

/*
 *
 * This file is part of %ProjectName%.
 *
 *    %ProjectName% is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    %ProjectName% is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with %ProjectName%.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef UARTMESSAGES_H
#define UARTMESSAGES_H
#include <QtCore>

#ifndef _ATTRIBUTE_PACKED_
#define _ATTRIBUTE_PACKED_ __attribute__ ((packed))
#endif

#define HEADER 0xFEFEFEFE
typedef enum{
    COMMAND_TAKEOFF = 1,
    COMMAND_LAND    = 2,
    COMMAND_TARGET  = 3,
    COMMAND_GPSTARG = 4,
    COMMAND_TRIM    = 5,
    COMMAND_EMERG   = 6,
    COMMAND_SYNC    = 7,

    DATA_GPS        = 51,
    DATA_VEL        = 52,
    DATA_GYR        = 53,
    DATA_BAT        = 54,
    DATA_ALTITUDE   = 55,
    DATA_STATUS     = 56,
    DATA_TIMESTAMP  = 57
}message_headers;

typedef struct _uart_pakket_t{
    quint8 header;
    quint8 size;

    quint8* data;
}_ATTRIBUTE_PACKED_ uart_pakket;

typedef struct _uart_message_t{
    quint32 sequence;
    //Here comes the data.
    uart_pakket* data[];
}_ATTRIBUTE_PACKED_ uart_message;

typedef struct _uart_takeoff_t{
    quint8 header;
    quint8 size;
}_ATTRIBUTE_PACKED_ uart_takeoff;

typedef struct _uart_land_t{
    quint8 header;
    quint8 size;
}_ATTRIBUTE_PACKED_ uart_land;

typedef struct _uart_trim_t{
    quint8 header;
    quint8 size;
}_ATTRIBUTE_PACKED_ uart_trim;

typedef struct _uart_target_t{
    quint8 header;
    quint8 size;

    quint32 altitude;
    float   relativeX;
    float   relativeY;
}_ATTRIBUTE_PACKED_ uart_target;

typedef struct _uart_gpstarget_t{
    quint8 header;
    quint8 size;

    quint32 altitude;
    float   latitude;
    float   longitude;
}_ATTRIBUTE_PACKED_ uart_gpstarget;

typedef struct _uart_gpsloc_t{
    quint8 header;
    quint8 size;

    quint32 altitude;
    float   latitude;
    float   longitude;
    float   bearing;
}_ATTRIBUTE_PACKED_ uart_gpsloc;

typedef struct _uart_gyr_t{
    quint8 header;
    quint8 size;

    float   x;
    float   y;
    float   z;
}_ATTRIBUTE_PACKED_ uart_gyr;

typedef struct _uart_vel_t{
    quint8 header;
    quint8 size;

    float   x;
    float   y;
    float   z;
}_ATTRIBUTE_PACKED_ uart_vel;

typedef struct _uart_bat_t{
    quint8 header;
    quint8 size;

    quint8 perc;
}_ATTRIBUTE_PACKED_ uart_bat;

typedef struct _uart_altitude_t{
    quint8 header;
    quint8 size;

    quint32 altitude;
}_ATTRIBUTE_PACKED_ uart_altitude;

typedef struct _uart_timestamp_t{
    quint8 header;
    quint8 size;

    quint32 timestamp;
}_ATTRIBUTE_PACKED_ uart_timestamp;

#endif // UARTMESSAGES_H
